package com.jic.manager.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.CmsTpageMapper;
import com.jic.manager.entity.CmsTpage;
import com.jic.manager.service.CmsTpageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 模板页信息表
 * @author : 
 * @email : 
 * @since : 2020-03-05 12:01:34
 * @version : v1.0.0
 */
@Service
public class CmsTpageServiceImpl implements CmsTpageService{

    @Autowired
    private CmsTpageMapper cmsTpageMapper;

    @Override
    public long insert(CmsTpage cmsTpage) {
        long flag = cmsTpageMapper.insert(cmsTpage);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return cmsTpageMapper.delete(id);
    }

    @Override
    public long update(CmsTpage cmsTpage) {
        return cmsTpageMapper.update(cmsTpage);
    }

    @Override
    public CmsTpage queryByPrimaryKey(Long id){
        return cmsTpageMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<CmsTpage> query(CmsTpage cmsTpage){
        return cmsTpageMapper.query(cmsTpage);
    }

    @Override
    public PageResult<CmsTpage> queryPage(CmsTpage cmsTpage, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CmsTpage> list = cmsTpageMapper.queryPage(startIndex, pageQuery.getLimit(), cmsTpage);
        long count = cmsTpageMapper.queryPageCount(cmsTpage);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

	@Override
	public PageResult<CmsTpage> queryPages(CmsTpage cmsTpage, Page pageQuery) {
		 //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CmsTpage> list = cmsTpageMapper.queryPages(startIndex, pageQuery.getLimit(), cmsTpage);
        long count = cmsTpageMapper.queryPagesCount(cmsTpage);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
	}
}